package org.ricks.common.db;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author chenwei
 * @Title:
 * @Package
 * @Description:
 * @date 2020/12/2316:48
 */
public class ArrayHandler implements ResultSetHandler<Object[]> {
    static final RowProcessor ROW_PROCESSOR = new BasicRowProcessor();
    private static final Object[] EMPTY_ARRAY = new Object[0];
    private final RowProcessor convert;

    public ArrayHandler() {
        this(ROW_PROCESSOR);
    }

    public ArrayHandler(RowProcessor convert) {
        this.convert = convert;
    }

    public Object[] handle(ResultSet rs) throws SQLException {
        return rs.next() ? this.convert.toArray(rs) : EMPTY_ARRAY;
    }
}
